home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / Image / GIS / Renderer / SVG.php < prev   
PHP Script  |  2004-03-24  |  3KB  |  134 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: SVG Renderer                                   |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and             |
  7. // |                         Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  8. // +------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,        |
  10. // | that is available at http://www.php.net/license/3_0.txt.               |
  11. // | If you did not receive a copy of the PHP license and are unable to     |
  12. // | obtain it through the world-wide-web, please send a note to            |
  13. // | license@php.net so we can mail you a copy immediately.                 |
  14. // +------------------------------------------------------------------------+
  15. //
  16. // $Id: SVG.php,v 1.5 2004/01/01 10:31:39 sebastian Exp $
  17. //
  18.  
  19. require_once 'Image/GIS/Renderer.php';
  20. require_once 'XML/SVG.php';
  21.  
  22. /**
  23. * SVG Renderer.
  24. *
  25. * @version  $Revision: 1.5 $
  26. * @since    Image_GIS 1.0.0
  27. */
  28. class Image_GIS_Renderer_SVG extends Image_GIS_Renderer {
  29.     /**
  30.     * SVG Document.
  31.     *
  32.     * @var XML_SVG $svg
  33.     */
  34.     var $svg;
  35.  
  36.     /**
  37.     * SVG Groups.
  38.     *
  39.     * @var XML_SVG_Group[]
  40.     */
  41.     var $svgGroups = array();
  42.  
  43.     /**
  44.     * Constructor.
  45.     *
  46.     * @param  mixed   $width
  47.     * @param  integer $sizyY
  48.     * @param  boolean $debug
  49.     * @access public
  50.     */
  51.     function Image_GIS_Renderer_SVG($width, $height, $debug) {
  52.         $this->Image_GIS_Renderer($width, $height, $debug);
  53.  
  54.         $this->svg = new XML_SVG_Document(
  55.           array(
  56.             'width'  => $width,
  57.             'height' => $height
  58.           )
  59.         );
  60.     }
  61.  
  62.     /**
  63.     * Draws a line from ($x1, $y1) to ($x2, $y2)
  64.     * using the color rgb($r, $g, $b).
  65.     *
  66.     * @param  float   $x1
  67.     * @param  float   $y1
  68.     * @param  float   $x2
  69.     * @param  float   $y2
  70.     * @param  float   $r
  71.     * @param  float   $g
  72.     * @param  float   $b
  73.     * @access public
  74.     */
  75.     function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) {
  76.         $group = md5($r . $g . $b);
  77.  
  78.         if (!isset($this->svgGroups[$group])) {
  79.             $this->svgGroups[$group] = new XML_SVG_Group(
  80.               array(
  81.                 'style' => sprintf(
  82.                   'stroke:rgb(%s, %s, %s)',
  83.  
  84.                   $r,
  85.                   $g,
  86.                   $b
  87.                 )
  88.               )
  89.             );
  90.  
  91.             $this->svgGroups[$group]->addParent($this->svg);
  92.         }
  93.  
  94.         $line = new XML_SVG_Line(
  95.           array(
  96.             'x1'    => $x1,
  97.             'y1'    => $y1,
  98.             'x2'    => $x2,
  99.             'y2'    => $y2,
  100.           )
  101.         );
  102.  
  103.         $this->svgGroups[$group]->addChild($line);
  104.     }
  105.  
  106.     /**
  107.     * Saves the rendered image to a given file.
  108.     *
  109.     * @param  string  $filename
  110.     * @return boolean
  111.     * @access public
  112.     */
  113.     function saveImage($filename) {
  114.         if ($fp = @fopen($filename, 'w')) {
  115.             @fputs($fp, $this->svg->bufferObject());
  116.             @fclose($fp);
  117.  
  118.             return true;
  119.         }
  120.  
  121.         return false;
  122.     }
  123.  
  124.     /**
  125.     * Shows the rendered image.
  126.     *
  127.     * @access public
  128.     */
  129.     function showImage() {
  130.         $this->svg->printElement();
  131.     }
  132. }
  133. ?>
  134.